home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / H-I / HyperHackers.cpt / Hyper-Hackers Queue 1.0 / card_7135.txt < prev    next >
Text File  |  1989-02-26  |  2KB  |  75 lines

  1. -- card: 7135 from stack: in.0
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 3797
  5. -- name: 
  6.  
  7.  
  8. -- part contents for background part 1
  9. ----- text -----
  10.  
  11. Date: Wed, 4 Nov 87 11:06 EST
  12. From: David Bogartz <IDDAVIDB@aahbo.com>
  13.  
  14.  
  15. The scripts below show a quick and very dirty way to get HyperCard to
  16. send a message when the user presses a key (other than return, tab,
  17. and the arrow keys).  It doesn't work for number keys, and it probably
  18. isn't right for some applications, but it's simple and will probably
  19. work in many cases.
  20.  
  21. The basic idea is that there is an idle handler in the background
  22. script that looks in the message box and grabs whatever is there.
  23. Then, for each keystroke, it generates the event "key" with the char
  24. that the user pressed as a parameter.
  25.  
  26. The trick is how to deal with the message box.  It looks like the
  27. message box is hidden, but in point of fact you can't have the message
  28. box hidden because (as far as I can tell) whenever you put something
  29. into the message box, HyperCard shows it, even if the screen is
  30. locked.  So I have it visible, but offscreen.  (Of course, this only
  31. works on a small screen Mac.)
  32.  
  33. This application lets the user press the keys A through G to play the
  34. respective notes A through G on the harpsichord keyboard.
  35.  
  36. Background script
  37. =================
  38.  
  39. on idle
  40.   put the message box into k
  41.   if k is not empty then
  42.     repeat with i = 1 to length(k)
  43.       do "key " & quote & char i of k & quote
  44.     end repeat
  45.     put empty into the message box
  46.   end if
  47. end idle
  48.  
  49. on key c
  50.   play "harpsichord" tempo 200 c
  51. end key
  52.  
  53.  
  54. Stack script
  55. ============
  56.  
  57. on openStack
  58.   set the loc of msg to -473, 345
  59.   set blindtyping to true
  60. end openStack
  61.  
  62. ============
  63.  
  64. I'd be interested in any feedback or improvements on this code that
  65. you may have.  If you send messages directly to me, I will summarize
  66. to the net.
  67.  
  68. David S. Bogartz
  69. dsbogartz@amherst.bitnet
  70.  
  71.  
  72.  
  73. -- part contents for background part 45
  74. ----- text -----
  75. Keydown messages